<ul class="nav user-bar navbar-nav navbar-right">
  <% if current_user %>
  <li class="dropdown dropdown-avatar">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
      <%= user_avatar_tag(current_user, :sm, link: false) %> <span class="caret"></span>
    </a>
    <button class="navbar-toggle" type="button" data-toggle="dropdown" role="button" aria-expanded="false">
      <span class="sr-only">Toggle</span>
      <i class="fa fa-reorder"></i>
    </button>
    <%= render_list class: "dropdown-menu", role: "menu" do |li|
      li << link_to(current_user.login, main_app.user_path(current_user) )
      li << "<div class='divider'></div>"
      li << link_to(t("menu.edit_account_path"), main_app.edit_user_registration_path)
      li << link_to(t("menu.notes"), main_app.notes_path )
      li << link_to(t("menu.likes"), main_app.favorites_topics_path)
      if admin?
        li << "<div class='divider'></div>"
        if params[:controller].start_with?("admin")
          li << link_to("回到前台", main_app.root_path)
        else
          li << link_to(t("menu.admin"), "/admin")
        end
      end
      li << "<div class='divider'></div>"
      li << link_to(t("common.logout"), main_app.destroy_user_session_path, method: "delete" )
    end %>
  </li>
  <% else %>
  <% if !Setting.sso_enabled? %>
  <li><%= link_to( t("common.register"), main_app.new_user_registration_path) %></li>
  <% end %>
  <li><%= link_to( t("common.login"), main_app.new_user_session_path ) %></li>
  <% end %>
</ul>

<ul class="nav navbar-nav user-bar navbar-right">
  <li class="nav-search hidden-xs hidden-sm">
    <form class="navbar-form form-search active" action="/search" method="GET">
      <div class="form-group">
        <input class="form-control" name="q" type="text" value="<%= params[:q] %>" placeholder="搜索本站内容" />
      </div>
      <i class="fa btn-search fa-search"></i>
    </form>
  </li>
  <% if current_user %>
  <%
  badge_class = ""
  badge_class = "new" if unread_notify_count > 0
  %>
  <li class="notification-count">
    <a href="<%= main_app.notifications_path %>" class="<%= badge_class %>" title="通知"><i class="fa fa-bell"></i><span class="count"><%= unread_notify_count %></span></a>
  </li>
  <li>
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
      <i class="fa fa-plus"></i> <span class="caret"></span>
    </a>
    <%= render_list class: "dropdown-menu", role: "menu" do |li|
      li << link_to(t("topics.new_topic"), main_app.new_topic_path)
      li << link_to(t("notes.new_note"), main_app.new_note_path) if Setting.has_module?(:note)
      if can? :create, Team
        li << "<div class='divider'></div>"
        li << link_to(t("teams.new_team"), main_app.new_team_path)
      end
    end %>
  </li>
  <% end %>
</ul>
